package com.aplink.generic.xmlparser.ctrlformat;

import org.w3c.dom.Node;

import android.text.TextUtils;

import com.aplink.generic.pojo.controlspec.CheckBoxSpec;
import com.aplink.generic.xmlparser.XMLPaserUtil;

public class CheckBoxFormat {
    public static final String DISABLE_GROUP = "disableGroup";
    public static final String HIDE_GROUP = "hideGroup";
    public static final String INVISIBILITY_GROUP = "invisibilityGroup";
    public static final String TEXT_OFF = "textOff";
    public static final String TEXT_ON = "textOn";
    public static final String VALUE_OFF = "valueOff";
    public static final String VALUE_ON = "valueOn";

    public static CheckBoxSpec parse(final Node node) {
        final CheckBoxSpec switchSpec = new CheckBoxSpec();
        if (node.hasAttributes()) {
            String value = XMLPaserUtil.getAttrValue(node,
                    CheckBoxFormat.VALUE_ON);
            if (!TextUtils.isEmpty(value)) {
                switchSpec.setValueOn(value);
            }

            value = XMLPaserUtil.getAttrValue(node, CheckBoxFormat.VALUE_OFF);
            if (!TextUtils.isEmpty(value)) {
                switchSpec.setValueOff(value);
            }
            value = XMLPaserUtil.getAttrValue(node, CheckBoxFormat.TEXT_ON);
            if (!TextUtils.isEmpty(value)) {
                switchSpec.setTextOn(value);
            }

            value = XMLPaserUtil.getAttrValue(node, CheckBoxFormat.TEXT_OFF);
            if (!TextUtils.isEmpty(value)) {
                switchSpec.setTextOff(value);
            }
            value = XMLPaserUtil.getAttrValue(node,
                    CheckBoxFormat.DISABLE_GROUP);
            if (!TextUtils.isEmpty(value)) {
                switchSpec.setDisableGroupID(value);
            }
            value = XMLPaserUtil.getAttrValue(node, CheckBoxFormat.HIDE_GROUP);
            if (!TextUtils.isEmpty(value)) {
                switchSpec.setHideGroupID(value);
            }
            value = XMLPaserUtil.getAttrValue(node,
                    CheckBoxFormat.INVISIBILITY_GROUP);
            if (!TextUtils.isEmpty(value)) {
                switchSpec.setVisibilityGroupID(value);
            }
        }
        return switchSpec;
    }
}
